import { Controller, Get, Post, Body, Patch, Param, Delete, Req, Put } from '@nestjs/common';
import { MenusService } from './menus.service';
import { CreateMenuDto } from './dto/create-menu.dto';
import { UpdateMenuDto } from './dto/update-menu.dto';
import { wrapperResponse } from '../../utils';

@Controller('menus')
export class MenusController {
  constructor(private readonly menusService: MenusService) {}

  @Get()
  getAllMenu(){
    return wrapperResponse(
      this.menusService.findAllMenu(),
      '获取菜单成功'
    );
  }

  // @Get()
  // getAllMenuByToken(@Req() req){
  //   return wrapperResponse(
  //     this.menusService.findAllMenuByUsername(req.user.username),
  //     '获取菜单成功'
  //   );
  // }

  @Get('active')
  getActiveMenuByToken(@Req() req){
    return wrapperResponse(
      this.menusService.findActiveMenuByUsername(req.user.username),
      '获取菜单成功'
    );
  }

  @Post()
  create(@Body() createMenuDto: CreateMenuDto) {
    return wrapperResponse(
      this.menusService.create(createMenuDto),
      '创建菜单成功'
    )
  }

  @Put()
  update(@Body() updateMenuDto: UpdateMenuDto) {
    return wrapperResponse(
      this.menusService.update(updateMenuDto),
      '编辑菜单成功'
    )
  }

  @Delete()
  remove(@Body('id') id: number) {
    return this.menusService.remove(+id);
  }

  // @Get()
  // findAll() {
  //   return this.menusService.findAll();
  // }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.menusService.findOne(+id);
  }

}
